﻿describe("Strategies/PointingPair", function () {

    var pointingPair;

    beforeEach(function () {
        pointingPair = new Strategies.PointingPair();
    });

    describe("should find by:", function () {

        it("row", function () {

            var grid = "--9--2374--4-7-59-7--9-4--1861349257-9-7614384378251699--4-7--3-7----94--4829-715";
            var gridModel = GridModel.fromShortString(grid);
            SolvingHelper.fillCandidates(gridModel);

            //do
            var performResult = pointingPair.perform(gridModel);

            //expect
            expect(performResult.candidate).toEqual(8);
            expect(performResult.sourceRegionId).toEqual(2);
            expect(performResult.mode).toEqual('row');
            var expectedContainingCells = [gridModel.cells[2][6], gridModel.cells[2][7]];
            expect(performResult.containingCells).toEqual(jasmine.arrayContaining(expectedContainingCells));
            var expectedTargetCells = gridModel.cells[2];
            expect(performResult.targetCells).toEqual(jasmine.arrayContaining(expectedTargetCells));

            var expectedGridModel = GridModel.fromShortString(grid);
            SolvingHelper.fillCandidates(expectedGridModel);
            expectedGridModel.cells[2][1].candidates.remove(8);
            expectedGridModel.cells[2][4].candidates.remove(8);
            expect(gridModel).toEqual(expectedGridModel);
        });

        it("column", function () {

            var grid = "5--914832941823---283---94143-1-2-8-6-23-81-481--4-2-312-48-3--3-47-16287-823-41-";
            var gridModel = GridModel.fromShortString(grid);
            SolvingHelper.fillCandidates(gridModel);

            //do
            var performResult = pointingPair.perform(gridModel);

            //expect
            expect(performResult.candidate).toEqual(6);
            expect(performResult.sourceRegionId).toEqual(7);
            expect(performResult.mode).toEqual('column');
            var expectedContainingCells = [gridModel.cells[6][5], gridModel.cells[8][5]];
            expect(performResult.containingCells).toEqual(jasmine.arrayContaining(expectedContainingCells));
            var expectedTargetCells = gridModel.cellsByColumn[5];
            expect(performResult.targetCells).toEqual(jasmine.arrayContaining(expectedTargetCells));

            var expectedGridModel = GridModel.fromShortString(grid);
            SolvingHelper.fillCandidates(expectedGridModel);
            expectedGridModel.cells[2][5].candidates.remove(6);
            expectedGridModel.cells[5][5].candidates.remove(6);

            expect(gridModel).toEqual(expectedGridModel);
        });


    });
});

